Skip to content

refactor: PipelineBuilder LIFO to FIFO for intuitive middleware ordering - #438

Merged
JusterZhu merged 2 commits into
GeneralLibrary:masterfrom
JusterZhu:refactor/pipeline-fifo
May 26, 2026
Merged

refactor: PipelineBuilder LIFO to FIFO for intuitive middleware ordering#438
JusterZhu merged 2 commits into
GeneralLibrary:masterfrom
JusterZhu:refactor/pipeline-fifo

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #436. Change PipelineBuilder from ImmutableStack (LIFO) to ImmutableQueue (FIFO) so that middleware registration order equals execution order.

Motivation

The LIFO stack caused the MacStrategy pipeline bug (fixed in #436) — registration order UseMiddleware<A>().UseMiddleware<B>() executes B before A, which is counterintuitive. With FIFO, the code says what it does.

Changes

File Change
Pipeline/PipelineBuilder.cs ImmutableStackImmutableQueue, PushEnqueue
Strategy/WindowsStrategy.cs Register Hash → Compress → Patch (same execution under FIFO)
Strategy/LinuxStrategy.cs Same
Strategy/MacStrategy.cs Same, also UseMiddlewareUseMiddlewareIf for consistency

All three platforms now register in the same order:

HashMiddleware → CompressMiddleware → PatchMiddleware
     ①SHA256        ②Decompress         ③Differential

Test plan

  • All 960 CoreTest tests pass

🤖 Generated with Claude Code

…ImmutableQueue)

The LIFO stack caused middleware execution order to be the reverse of
registration order, which was the root cause of the MacStrategy pipeline
bug fixed in GeneralLibrary#436. With FIFO (ImmutableQueue), registration order now
equals execution order for intuitive API semantics.

- PipelineBuilder: ImmutableStack → ImmutableQueue, Push → Enqueue
- All OS strategies: register Hash → Compress → Patch (executes in same order)
- MacStrategy: also changed to UseMiddlewareIf<PatchMiddleware> for consistency

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 26, 2026 06:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors PipelineBuilder to execute middleware in FIFO (registration) order by switching from ImmutableStack to ImmutableQueue, and updates platform strategies so registration order matches intended execution order (Hash → Compress → Patch).

Changes:

  • Refactor PipelineBuilder storage from stack (LIFO) to queue (FIFO) so middleware executes in registration order.
  • Reorder Windows/Linux middleware registration to HashMiddlewareCompressMiddlewarePatchMiddleware (conditional).
  • Make MacStrategy’s patch middleware conditional via UseMiddlewareIf to match other platforms.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/c#/GeneralUpdate.Core/Pipeline/PipelineBuilder.cs Switch middleware collection to FIFO queue and iterate in registration order.
src/c#/GeneralUpdate.Core/Strategy/WindowsStrategy.cs Reorder middleware registration to match FIFO execution semantics.
src/c#/GeneralUpdate.Core/Strategy/LinuxStrategy.cs Reorder middleware registration to match FIFO execution semantics.
src/c#/GeneralUpdate.Core/Strategy/MacStrategy.cs Make Patch middleware conditional and align registration order with other platforms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to +15
/// <summary>
/// LIFO��Last In First Out.
/// LIFO£¬Last In First Out.
/// </summary>
private ImmutableStack<IMiddleware> _middlewareStack = ImmutableStack<IMiddleware>.Empty;
private ImmutableQueue<IMiddleware> _middlewareQueue = ImmutableQueue<IMiddleware>.Empty;
foreach (var middleware in _middlewareStack)
foreach (var middleware in _middlewareQueue)
{
await middleware.InvokeAsync(context);
@JusterZhu
JusterZhu merged commit d2496f1 into GeneralLibrary:master May 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants